-- spell_bonus
-- create by dengc
-- 随机卷轴奖励
-- 参数列说明：(num, a~b) num数量，a ~ b阶

return {
    -- 使用道具
    useProperty = function(target, bonusId, info)
        local range = string.explode(info[2], "~");
        local min, max;

        if #range > 1 then
            min = tonumber(range[1]);
            max = tonumber(range[2]);
        else
            min = tonumber(range[1]);
            max = min;
        end

        assert(max >= min);

        local count;
        if type(info[1]) == 'number' then
            count = tonumber(info[1]);
        else
            range = string.explode(info[1], "~");
            local num1, num2;

            if #range > 1 then
                num1 = tonumber(range[1]);
                num2 = tonumber(range[2]);
            else
                num1 = tonumber(range[1]);
                num2 = num1;
            end
            assert(num2 >= num1);
            count = num1 + DungeonM.getRandSeed("property_spell_bonus") % (num2 - num1 + 1);
        end

        local differ = max - min;
        for i = 1, count do
            local rand = DungeonM.getRandSeed("property_spell_bonus");
            local  rank = min + rand % (differ + 1);

            local spells = SpellM.getSpellByRank(rank);

            rand = DungeonM.getRandSeed("property_spell_bonus");
            local spell = spells[rand % #spells + 1];

            BonusM.doBonus({ 1, spell, 1, }, "spell bonus");
        end
    end,
};
